package org.miyuki4j.cfgtool;

import lombok.extern.slf4j.Slf4j;

/**
 * @Desc
 * @Author miyuki4j
 * @Date 2025/7/28/星期一 17:29
 * @Version 1.0
 */
@Slf4j
public abstract class CfgApp {

    protected String[] args;

    public abstract RunModeEnum runMode();

    public void init(String[] args) {
        log.debug("✅ {} init| args:{}", getClass().getName(), String.join(" ", args));
        this.args = args;
    }

    protected abstract void run() throws Exception;

    public final void asyncRun() {
        Thread thread = new Thread(() -> {
            try {
                run();
            } catch (Exception e) {
                log.error("❌ {} run error", getClass().getName(), e);
                CfgAppKeeper.done();
            }
        }, "Thread-" + getClass().getSimpleName());
        thread.start();
    }

    public void exit() {
        log.debug("✅ {} exit", getClass().getName());
    }

}
